﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using DispatchAssist.BusinessLogical.BLL;


namespace DispatchAssist.WebService
{
    public class Global : System.Web.HttpApplication
    {
        private System.Timers.Timer timer = null;

        protected void Application_Start(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure();

            string intervel = System.Configuration.ConfigurationManager.AppSettings["TimerIntervel"];
            timer = new System.Timers.Timer(string.IsNullOrEmpty(intervel) ? 60000 : int.Parse(intervel));
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Start();
        }

        private void timer_Elapsed(object s, System.Timers.ElapsedEventArgs e)
        {
            timer.Stop();

            try
            {
                CarolLib.Log.Instance.Warn("begin timer_Elapsed");
                ClientInfoCacheHelper.GetNewCacheData();
                CarolLib.Log.Instance.Warn("end timer_Elapsed");
            }
            catch
            {
                CarolLib.Log.Instance.Warn("!!!!!!!!!!! error during timer_Elapsed !!!!!!!!!!!");
            }
            finally
            {
                timer.Start();
                CarolLib.Log.Instance.Warn("start timer_Elapsed");
            }
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            
        }
    }
}